﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BestLifePOS_Core.Data.Commands;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Fascade;
using System.Linq;
namespace BestLifePOS_PresentationLayer
{
    public partial class frmVenderPayment : Form
    {
        public frmVenderPayment()
        {
            InitializeComponent();
        }

        private void btnVendorPay_VNew_Click(object sender, EventArgs e)
        {
            txtVendorPay_VPayId.Text = Vendor_BillDAO.GetNewVendorPayId().ToString();
        }

        private void FillVendorNameDropDown()
        {
            //Fill the DataGrid
            List<Supplier> LvList = SupplierDAO.GetAllSupplier();
            DataTable LvTable = new DataTable();
            //dgvGRN.DataSource = LvTable3;

            //cmbCategory.DataSource = LvTable;
            LvTable.Columns.Add("SupID");
           // LvTable.Columns.Add("CategoryName");

            string lvtest = "";

            foreach (Supplier LvSup in LvList)
            {
                //LvTable = (DataTable)cmbCategory.DataSource;

                LvTable.Rows.Add(LvTable.NewRow());

                lvtest = LvSup.Sup_ID.ToString() + '-' + LvSup.Sup_Name.ToString();
                LvTable.Rows[LvTable.Rows.Count - 1][0] = lvtest;
                //LvTable.Rows[LvTable.Rows.Count - 1][0] = LvCategory.Cat_ID.ToString() +'-' + LvCategory.Cat_Name.ToString();
                //LvTable.Rows[LvTable.Rows.Count - 1][1] = LvSubCategory.Subcat_ID.ToString();


            }

            cmbVendorPay_VName.DisplayMember = "SupID";
            cmbVendorPay_VName.ValueMember = "SupID";
            cmbVendorPay_VName.DataSource = LvTable;
            //cmbCategory.DataBindings();



        }

        private void frmVenderPayment_Load(object sender, EventArgs e)
        {
            FillVendorNameDropDown();
            txtVendorPay_VPayDate.Text = DateTime.Now.ToString();
        }

        private void btnVendorPay_VSave_Click(object sender, EventArgs e)
        {
            SaveVendorPayment();
            MessageBox.Show("VENDOR PAYMENT STATUS WAS SUCCESFULLY POSTED");
        }

        private int SaveVendorPayment()
        {

            Vendor_Bill LvVendorPay = CollectVendorPayFigures();
            if (LvVendorPay != null)
            {
                return Vendor_BillDAO.SaveVendorPay(LvVendorPay);
            }
            else
            {
                return 0;
            }
        }

        private Vendor_Bill CollectVendorPayFigures()
        {


            try
            {

                Vendor_Bill LvVendorPay = new Vendor_Bill();

                LvVendorPay.SB_No = txtVendorPay_VPayId.Text.ToString();
                LvVendorPay.Ven_No = cmbVendorPay_VName.Text.ToString().Substring(0, 8);
                LvVendorPay.Ven_date = DateTime.Parse(txtVendorPay_VPayDate.Text.ToString());
                LvVendorPay.Total = decimal.Parse(txtVendorPay_VPayTotal.Text.ToString());
                LvVendorPay.Po_Id = txtPoNo.Text.ToString();
                LvVendorPay.User_Id = "1";
                LvVendorPay.Date_Create = DateTime.Parse(DateTime.Now.ToString());
                LvVendorPay.Last_Modify = DateTime.Parse(DateTime.Now.ToString());
                LvVendorPay.User_Modify ="1";


                return LvVendorPay;
            }
            catch (Exception)
            {
                return null;
            }
        }
    }
}
